//
//  MCPersonInformationTableViewCell.m
//  TLYL
//
//  Created by MC on 2017/6/14.
//  Copyright © 2017年 TLYL01. All rights reserved.
//

#import "MCPersonInformationTableViewCell.h"

#define HEIGHT_LINE  50

@interface MCPersonInformationTableViewCell ()
/*
 * 打底
 */
@property (nonatomic,strong)UIView * view_back;





/*
 * 手机号
 */
@property (nonatomic,strong)UIImageView * imgV_phone;
@property (nonatomic,strong)UITextField * textField_phone;
@property (nonatomic,strong)UILabel * lab_tip;
@property (nonatomic,strong)UIView * view_line1;

/*
 * 邮箱
 */
@property (nonatomic,strong)UIImageView * imgV_email;
@property (nonatomic,strong)UITextField * textField_email;
@property (nonatomic,strong)UIView * view_line2;

/*
 * 姓名
 */
@property (nonatomic,strong)UIImageView * imgV_name;
@property (nonatomic,strong)UITextField * textField_name;


@end

@implementation MCPersonInformationTableViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self){
        [self initView];
    }
    return self;
}

- (void)initView{
    
    self.backgroundColor=[UIColor clearColor];
    
    
    /*
     * 打底
     */
    _view_back=[[UIView alloc]init];
    [self addSubview:_view_back];
    _view_back.backgroundColor=[UIColor whiteColor];
    _view_back.layer.cornerRadius=5;
    _view_back.clipsToBounds=YES;
    _view_back.layer.borderColor = RGB(200, 200, 200).CGColor;
    _view_back.layer.borderWidth = 0.5;
    _view_back.frame=CGRectMake(10, 0, G_SCREENWIDTH-20, 150);
    

    
    
    /*
     * 手机号
     */
    _imgV_phone=[[UIImageView alloc]init];
    _imgV_phone.backgroundColor=[UIColor cyanColor];
    [_view_back addSubview:_imgV_phone];
    
    [_imgV_phone mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_view_back.mas_top).offset(10);
        make.left.equalTo(_view_back.mas_left).offset(10);
        make.width.mas_equalTo(30);
        make.height.mas_equalTo(30);
    }];
    
    _textField_phone = [[UITextField alloc] init];

    [self setTextField:_textField_phone WithPlaceholder:@"11位手机号码" and:UIKeyboardTypeNumberPad];

    [_textField_phone mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_view_back.mas_top).offset(0);
        make.left.equalTo(_view_back.mas_left).offset(50);
        make.right.equalTo(_view_back.mas_right).offset(-50);
        make.height.mas_equalTo(HEIGHT_LINE);
    }];
    
    
    _lab_tip =[[UILabel alloc]initWithFrame:CGRectZero];
    _lab_tip.alpha=0.8;
    _lab_tip.textColor=RGB(69, 142, 226);
    _lab_tip.font=[UIFont systemFontOfSize:12];
    _lab_tip.text =@"(选填)";
    _lab_tip.textAlignment=NSTextAlignmentRight;
    [_view_back addSubview:_lab_tip];
    [_lab_tip mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(_view_back.mas_top);
        make.centerY.equalTo(_textField_phone.mas_centerY);
        make.width.mas_equalTo(50);
        make.right.equalTo(_view_back.mas_right).offset(-10);
        
    }];
    
    _view_line1=[[UIView alloc]init];
    [_view_back addSubview:_view_line1];
    _view_line1.backgroundColor=RGB(200, 200, 200);
    _view_line1.frame=CGRectMake(0, HEIGHT_LINE, G_SCREENWIDTH, 0.5);
    
    
    
    /*
     * 邮箱
     */
    _imgV_email=[[UIImageView alloc]init];
    _imgV_email.backgroundColor=[UIColor cyanColor];
    [_view_back addSubview:_imgV_email];
    
    [_imgV_email mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_view_line1.mas_bottom).offset(9.5);
        make.left.equalTo(_view_back.mas_left).offset(10);
        make.width.mas_equalTo(30);
        make.height.mas_equalTo(30);
    }];
    
    _textField_email=[[UITextField alloc] init];
    _textField_email.tag=1002;
    [self setTextField:_textField_email WithPlaceholder:@"请输入你的常用邮箱" and:UIKeyboardTypeEmailAddress];

    

    [_textField_email mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_view_line1.mas_bottom).offset(0);
        make.left.equalTo(_view_back.mas_left).offset(50);
        make.right.equalTo(_view_back.mas_right).offset(-50);
        make.height.mas_equalTo(HEIGHT_LINE);
    }];

    _view_line2=[[UIView alloc]init];
    [_view_back addSubview:_view_line2];
    _view_line2.backgroundColor=RGB(200, 200, 200);
    _view_line2.frame=CGRectMake(0, HEIGHT_LINE*2, G_SCREENWIDTH, 0.5);
   
    
    /*
     * 姓名
     */
    _imgV_name=[[UIImageView alloc]init];
    _imgV_name.backgroundColor=[UIColor cyanColor];
    [_view_back addSubview:_imgV_name];
    
    [_imgV_name mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_view_line2.mas_bottom).offset(9.5);
        make.left.equalTo(_view_back.mas_left).offset(10);
        make.width.mas_equalTo(30);
        make.height.mas_equalTo(30);
    }];
    
    _textField_name=[[UITextField alloc] init];
    _textField_name.tag=1003;
    [self setTextField:_textField_name WithPlaceholder:@"请输入你的真实姓名" and:UIKeyboardTypeDefault];
    [_textField_name mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_view_line2.mas_bottom).offset(0);
        make.left.equalTo(_view_back.mas_left).offset(50);
        make.right.equalTo(_view_back.mas_right).offset(-50);
        make.height.mas_equalTo(HEIGHT_LINE);
    }];
    

}

-(void)setTextField:(UITextField*)textField WithPlaceholder:(NSString *)placeholder and:(UIKeyboardType)type{
    textField.placeholder=placeholder;
    textField.borderStyle = UITextBorderStyleNone;
    textField.backgroundColor=[UIColor whiteColor];
    textField.font = [UIFont systemFontOfSize:15];
    textField.textColor = RGB(100, 100, 100);
    textField.textAlignment = NSTextAlignmentLeft;
    textField.returnKeyType = UIReturnKeyDone;
    textField.keyboardType = type;
    [textField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:(UIControlEventEditingChanged)];
    [_view_back addSubview:textField];
    
}


-(void)relayOutConstraints{
   
    
}

-(void)setDataSource:(id)dataSource{
    _dataSource=dataSource;
    
}

-(void)textFieldDidChange:(UITextField *)textfield{
    //手机号
    if (textfield.tag==1001) {
         //11位电话号码
        if (_textField_phone.text.length>10) {
            _textField_phone.text =  [_textField_phone.text substringToIndex:11];
        }
    //邮箱
    }else if (textfield.tag==1002){
    
        
    //姓名
    }else if (textfield.tag==1003){
        
    }
}

+(CGFloat)computeHeight:(id)info{
    
    return 150;
    
}


- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

@end
